#include <QtGui>
#include "measureform.h"
#include "configdlg.h"
#include "measform.h"
#include "calbform.h"
#include "masterconfigform.h"
#include "../core/ctrl.h"
#include "../core/ctrlthread.h"


MeasureForm::MeasureForm(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	normalButton = ui.normalButton;
	masterButton = ui.masterButton;
	settingsButton = ui.settingsButton;
	backButton = ui.backButton;

	// set font size
	QFont font = this->font();
	font.setPixelSize(font.pointSize() * 4 / 3);
	setFont(font);

	setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
	showMaximized();

	connect(normalButton, SIGNAL(clicked()), this, SLOT(buttonsClicked()));
	connect(masterButton, SIGNAL(clicked()), this, SLOT(buttonsClicked()));
	connect(settingsButton, SIGNAL(clicked()), this, SLOT(buttonsClicked()));
	connect(backButton, SIGNAL(clicked()), this, SLOT(buttonsClicked()));
}


MeasureForm::~MeasureForm()
{
	delete normalButton;
	delete masterButton;
	delete settingsButton;
	delete backButton;
}


void MeasureForm::buttonsClicked()
{
	QPushButton *button = qobject_cast<QPushButton *>(sender());

	Ctrl *ctrl = Ctrl::getInstance();
	CtrlThread *thread = ctrl->getCtrlThread();

	if(button == normalButton){
		meas_form = new MeasForm;
		disconnect(thread, SIGNAL(measDataReady()), 0, 0);
		connect(thread, SIGNAL(measDataReady()), meas_form, SLOT(showMeasData()));
		meas_form->show();

	}else if(button == masterButton){
/*		
		calb_form = new CalbForm;
		if(calb_form->getHueList() == false){
			// 没有有效的光量项目
			delete calb_form;
			QMessageBox::warning(this, tr("CALIBRATION"), tr("NO VALID HUE,VL,DLM ITEM"));
		}else{
			disconnect(thread, SIGNAL(measDataReady()), 0, 0);
			connect(thread, SIGNAL(measDataReady()), calb_form, SLOT(showMasterResult()));
			calb_form->show();	
		}
*/
		MasterConfigForm *master_config_form = new MasterConfigForm;
		if(master_config_form->PrepareHueList()){
			master_config_form->show();
		}else{
			delete master_config_form;
			QMessageBox::warning(this, tr("CALIBRATION"), tr("NO VALID HUE,VL,DLM ITEM"));
		}
	}else if(button == settingsButton){
		ConfigDlg *dlg = new ConfigDlg;
		dlg->exec();
		delete dlg;

	}else if(button == backButton){
		delete this;
	}
}
